package com.egreen.user.controller;


import com.egreen.common.Result;
import com.egreen.common.States;
import com.egreen.common.pojo.DTO.user.userServiceDTO.CommodityExchangeDTO;
import com.egreen.common.pojo.DTO.user.userServiceDTO.CompleteInformationDTO;
import com.egreen.common.pojo.DTO.user.userServiceDTO.SignUpDTO;
import com.egreen.user.service.IUserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;


    @ApiOperation(value = "注册", notes = "通过调用signUp方法，完成注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true),
            @ApiImplicitParam(name = "phone", value = "手机号", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true),
            @ApiImplicitParam(name = "validCode", value = "验证码", required = true),
            @ApiImplicitParam(name = "invitationCode", value = "邀请码,可以为空"),
            @ApiImplicitParam(name = "signUpDTO", value = "以上五个参数封装在此DTO中")
    })
    @PostMapping("/signUp")
    Result signUp(@Validated @RequestBody SignUpDTO signUpDTO) {
        userService.signUp(signUpDTO);
        return Result.OK(States.OK);
    }


    /*
     * 完善信息
     */
    @ApiOperation(value = "完善信息", notes = "通过调用completeInformation方法，完成完善信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userID", value = "用户ID", readOnly = true),
            @ApiImplicitParam(name = "email", value = "邮箱", readOnly = true),
            @ApiImplicitParam(name = "province", value = "省份", readOnly = true),
            @ApiImplicitParam(name = "city", value = "城市", readOnly = true),
            @ApiImplicitParam(name = "district", value = "区域", readOnly = true),
            @ApiImplicitParam(name = "community", value = "社区", readOnly = true),
            @ApiImplicitParam(name = "locationDetails", value = "详细地址", readOnly = true),
            @ApiImplicitParam(name = "completeInformationDTO", value = "以上七个参数封装在此DTO中")
    })

    @PostMapping("/completeInformation")
    Result completeInformation(@Validated @RequestBody CompleteInformationDTO completeInformationDTO) {
        userService.completeInformation(completeInformationDTO);
        return Result.OK(States.OK);
    }

    /**
     * 获取用户基本信息
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "获取用户基本信息", notes = "获取相关用户的基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "Long", required = true)
    })
    @GetMapping("/getUserMessage")
    Result getUserMessage(@RequestParam Long userId) {
        return new Result(userService.getUserMessage(userId), States.OK.getStates()
                , States.OK.getDescription());
    }

    @ApiOperation(value = "积分兑换商品", notes = "用户使用积分兑换商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "Long", required = true),
            @ApiImplicitParam(name = "commodityId", value = "商品ID", paramType = "Integer", required = true)
    })
    @PostMapping("/commodityExchange")
    Result commodityExchange(@Validated @RequestBody CommodityExchangeDTO commodityExchangeDTO) {
        userService.commodityExchange(commodityExchangeDTO);
        return Result.OK(States.OK);
    }

    @ApiOperation(value = "获取邀请码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "Long", required = true)
    })
    @GetMapping("/getInvitationCode")
    Result getInvitationCode(@RequestParam Long userId) {
        return Result.OK(userService.getInvitationCode(userId));
    }
}

